﻿#include "CPoolTaskRobRpt.h"
#include "CLogOper.h"

CPoolTaskRobRpt::CPoolTaskRobRpt(QObject *parent) : QObject(parent), QRunnable()
{
	setAutoDelete(true);//放到线程池之后，工作完自动析构(任务执行完毕,该对象自动销毁)

	m_pAllDataInfo = new CAllPdfRptDataInfo();
}

CPoolTaskRobRpt::~CPoolTaskRobRpt()
{
	if (m_pAllDataInfo != nullptr)
	{
		delete m_pAllDataInfo;
		m_pAllDataInfo = nullptr;
	}
}


//设置数据
void CPoolTaskRobRpt::setData(CPdfRptRobDataInfo &robDataInfo, CPdfRptBase *pRptBase, QString sRobSceneGuid)
{
	m_pRptBase = pRptBase;
	m_sRobSceneGuid = sRobSceneGuid;

	//机器人数据
	if (m_pAllDataInfo != nullptr)
	{
		m_pAllDataInfo->robDataInfo.m_sClientCompanyName = robDataInfo.m_sClientCompanyName;
		m_pAllDataInfo->robDataInfo.m_sTaskActionId = robDataInfo.m_sTaskActionId;
		m_pAllDataInfo->robDataInfo.m_sOutputPdfFolder = robDataInfo.m_sOutputPdfFolder;
		m_pAllDataInfo->robDataInfo.m_sRobPdfPathUrl = robDataInfo.m_sRobPdfPathUrl;
		m_pAllDataInfo->robDataInfo.m_sRobotName = robDataInfo.m_sRobotName;
		m_pAllDataInfo->robDataInfo.m_sTaskName = robDataInfo.m_sTaskName;
		m_pAllDataInfo->robDataInfo.m_sTaskTime = robDataInfo.m_sTaskTime;
		m_pAllDataInfo->robDataInfo.m_sComment = robDataInfo.m_sComment;
		m_pAllDataInfo->robDataInfo.m_sTaskStartTime = robDataInfo.m_sTaskStartTime;
		m_pAllDataInfo->robDataInfo.m_sTaskEndTime = robDataInfo.m_sTaskEndTime;
		m_pAllDataInfo->robDataInfo.m_sTaskStartElecVal = robDataInfo.m_sTaskStartElecVal;
		m_pAllDataInfo->robDataInfo.m_sTaskEndElecVal = robDataInfo.m_sTaskEndElecVal;
		m_pAllDataInfo->robDataInfo.m_sTaskState = robDataInfo.m_sTaskState;
		m_pAllDataInfo->robDataInfo.m_sPercentOfPass = robDataInfo.m_sPercentOfPass;
		m_pAllDataInfo->robDataInfo.m_sInspPointCount = robDataInfo.m_sInspPointCount;
		m_pAllDataInfo->robDataInfo.m_sInspItemCount = robDataInfo.m_sInspItemCount;
		m_pAllDataInfo->robDataInfo.m_sInspItemNorCnt = robDataInfo.m_sInspItemNorCnt;
		m_pAllDataInfo->robDataInfo.m_sInspItemAbnorCnt = robDataInfo.m_sInspItemAbnorCnt;
		m_pAllDataInfo->robDataInfo.m_nInspItemAbnorCnt = robDataInfo.m_nInspItemAbnorCnt;
		
		m_pAllDataInfo->robDataInfo.m_vecAbnorBriefList = robDataInfo.m_vecAbnorBriefList;
		m_pAllDataInfo->robDataInfo.m_vecFormInspPointInfo = robDataInfo.m_vecFormInspPointInfo;
		m_pAllDataInfo->robDataInfo.m_VecCotDetInfo = robDataInfo.m_VecCotDetInfo;
	}

}

void CPoolTaskRobRpt::run()
{
	if (m_pAllDataInfo == nullptr || m_pRptBase == nullptr)
	{
		return;
	}

	{
		SExecLog exLog;
		exLog.m_nAlarmLevel = enWorkInfo;
		exLog.m_sDescriptionl = A2T("开始输出机器人[%1]的巡检报告").arg(m_pAllDataInfo->robDataInfo.m_sRobotName);
		exLog.m_sDevName = m_pAllDataInfo->robDataInfo.m_sRobotName;
		exLog.m_sFuncName = A2T("报表");
		CLogOper::instance().addMsg(exLog);
	}

	//输出
	QString sErrMsg = "";
	m_pRptBase->optRobPdfRptInfo(*m_pAllDataInfo, sErrMsg);//机器人报表输出

	//CSqlOperRob::instance().updateRobPdfUrl(m_pAllDataInfo->robDataInfo.m_sTaskActionId, m_pAllDataInfo->robDataInfo.m_sRobPdfPathUrl, m_pAllDataInfo->robDataInfo.m_sOutputPdfFolder);//更新机器人报表PDF URL和本地路径

	{
		SExecLog exLog;
		exLog.m_nAlarmLevel = enWorkInfo;
		exLog.m_sDescriptionl = A2T("输出完毕机器人[%1]的巡检报告").arg(m_pAllDataInfo->robDataInfo.m_sRobotName);
		exLog.m_sDevName = m_pAllDataInfo->robDataInfo.m_sRobotName;
		exLog.m_sFuncName = A2T("报表");
		CLogOper::instance().addMsg(exLog);
	}
}
